from fastapi import status


class CustomException(Exception):
    def __init__(self, status_code=status.HTTP_400_BAD_REQUEST, message: str=None):
        self.status_code = status_code
        self.message = message

    def __str__(self):
        return self.message or ""  # 确保返回 message 而不是类名

class NotFoundException(CustomException):
    def __init__(self, status_code=status.HTTP_404_NOT_FOUND, message: str = None):
        super().__init__(status_code=status_code, message=message or "没有找到数据")

class ConflictException(CustomException):
    def __init__(self, status_code=status.HTTP_409_CONFLICT, message: str = None, ):
        super().__init__(status_code=status_code, message=message or "存在冲突")

class AuthenticateException(CustomException):
    def __init__(self, status_code=status.HTTP_401_UNAUTHORIZED, message:str=None):
        default_detail = "对不起，请先登录!" if status_code == status.HTTP_401_UNAUTHORIZED else "对不起，你没有所需的权限!"
        super().__init__(status_code=status_code, message=message or default_detail)